<template>
  <el-col :span="24" style="height: 100%; display: flex; flex-direction: column">
    <el-row class="menu-header" style="height: 75px; background-color: #334157">
      <el-icon class="el-icon-s-promotion" style="font-size: 35px"></el-icon>
      后台管理系统
    </el-row>
    <el-menu default-active="1" class="el-menu-vertical-demo menu" background-color="#334157" text-color="#fff"
      active-text-color="#ffd04b">
          <el-row>
        <el-submenu>
          <template slot="title">
            <i class="el-icon-s-opportunity"></i>
            <span>数据分析</span>
          </template>
          <el-menu-item @click="selectMenu('user')">
            <i class="el-icon-message-solid"></i>
            <span>大屏展示</span>
          </el-menu-item>
        </el-submenu>
      </el-row>
      <el-row :index="index" v-for="(item, index) in data.menu" :key="index">
        <template v-if="typeof item?.show === 'function'?item.show():item.show">
          <template v-if="!item['children'] || item['children'].length == 0">
            <el-menu-item :index="index" :key="index">
              <i :class="item['el-iconClass']"></i>
              <span slot="title">{{ item.name }}</span>
            </el-menu-item>
          </template>
          <el-submenu :index="index" v-else>
            <template slot="title">
              <i :class="item['el-iconClass']"></i>
              <span>{{ item.name }}</span>
            </template>
            <template v-if="item['children']">
              <el-menu-item :index="index + '_' + index_1" v-for="(item_1, index_1) in item.children.filter(cell =>typeof cell?.show === 'function'?cell.show():cell.show)"
                :key="index + '_' + index_1" @click.native="selectMenu(item_1)">
                <i :class="item_1['el-iconClass']"></i>
                <span :index="index + '_' + index_1">{{ item_1.name }}</span>
              </el-menu-item>
            </template>
          </el-submenu>
        </template>
      </el-row>

      <!-- 原来的用户中心,现在简化成首页免得换 -->
      <!-- <el-row>
        <el-submenu>
          <template slot="title">
            <i class="el-icon-s-opportunity"></i>
            <span>用户中心</span>
          </template>
          <el-menu-item @click="selectMenu('user')">
            <i class="el-icon-message-solid"></i>
            <span>个人配置</span>
          </el-menu-item>
        </el-submenu>
      </el-row> -->
    </el-menu>
  </el-col>
</template>

<script>
export default {
  name: 'cMenu',
  props: {
    data: {
      type: Object,
      required: true,
      default: () => { }
    }
  },
  mounted() {
    console.log('this.menu', this.data)
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath)
    },
    deleteRow(index, rows) {
      rows.splice(index, 1)
    },
    selectMenu(t) {
      if (t == 'user') {
        this.$emit('selectMenu', false, 'user')
      } else {
        this.$emit('selectMenu', t, 'user')
      }
    }
  }
}
</script>

<style scoped>
.menu {
  height: 100%;
  width: 100%;
  border: none !important;
  overflow: scroll;
}
.menu::-webkit-scrollbar {
  width: 0;
  height: 0;
}
.menu-header {
  text-align: center;
  text-align: center;
  line-height: 75px;
  letter-spacing: 0.1em;
  font-family: common;
  font-size: 22px;
  color: #f5d658;
}
</style>
